<template>
    <div class="derive_form">
        <div class="com_box pd_box">
            <div class="pro_title">托管基础信息</div>
            <el-form-item label="策略名称" prop="name" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <el-input v-model="subForm.name" placeholder="策略名称" style="width:200px" @change="setSessionStorage">
                </el-input>
            </el-form-item>
            <el-form-item label="选择托管对象" prop="ad_ids" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                <div class="flexbox flexcenter">
                    <div class="com_check flexbox flexcolumn">
                        <div class="check_head">账户</div>
                        <div class="check_search">
                            <el-input placeholder="请输入账户ID搜索" size="mini" clearable suffix-icon="el-icon-search" @change="getUser(1)" v-model="userQeury.advertiser_id">
                            </el-input>
                        </div>
                        <div class="check_content flex" v-loading="u_loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
                            <el-checkbox-group v-model="planQeury.advertiser_id" class="user_check" @change="selectUser">
                                <template v-for="item in userList">
                                    <el-tooltip effect="dark" :open-delay="500" :content="item.name+':'+item.advertiser_id" placement="top-start" :key="item.advertiser_id">
                                        <el-checkbox :label="item.advertiser_id">
                                            <span class="span-item">{{item.name}}</span>
                                        </el-checkbox>
                                    </el-tooltip>
                                </template>
                            </el-checkbox-group>
                        </div>
                        <div class="page_footer">
                            <el-pagination small :pager-count="4" @current-change="userChange" :current-page="userQeury.page" :page-size="userQeury.limit" layout="total,prev, pager, next" :total="user_count">
                            </el-pagination>
                        </div>
                    </div>
                    <div class="com_check border_r flexbox flexcolumn">
                        <div class="check_head">计划</div>
                        <div class="check_search">
                            <el-input placeholder="请输入计划ID搜索" size="mini" clearable suffix-icon="el-icon-search" v-model="planQeury.ad_id" @change="getPlan(1)">
                            </el-input>
                        </div>
                        <div class="all_check">
                            <el-checkbox v-model="is_all" v-if="planList.length>0" @change="selectAll">全选</el-checkbox>
                        </div>
                        <div class="check_content flex" v-loading="p_loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
                            <div class="user_check">
                                <template v-for="item in planList">
                                    <el-tooltip effect="dark" :open-delay="500" :content="item.name+':'+item.ad_id" placement="top-start" :key="item.ad_id">
                                        <el-checkbox v-model="item.check" @change="checkPlan(item)">
                                            <span class="span-item">{{item.name}}</span>
                                        </el-checkbox>
                                    </el-tooltip>
                                </template>
                            </div>
                        </div>
                        <div class="page_footer">
                            <el-pagination small :pager-count="4" @current-change="planChange" :current-page="planQeury.page" :page-size="planQeury.limit" layout="total,prev, pager, next" :total="plan_count">
                            </el-pagination>
                        </div>
                    </div>
                    <div class="com_check border_r mg_l_12 flexbox flexcolumn">
                        <div class="check_head flexbox flexcenter flexbetween">
                            <span>已选</span>
                            <el-link type="primary" :underline="false" @click="clearPlan">清空</el-link>
                        </div>
                        <div class="check_content">
                            <template v-for="(item,index) in subForm.ad_ids">
                                <el-tooltip effect="dark" :open-delay="500" :content="item.name+':'+item.ad_id" placement="top-start" :key="index">
                                    <div class="has_item flexbox flexcenter flexbetween">
                                        <div class="line_one">{{item.name}}</div>
                                        <el-link icon="el-icon-close" :underline="false" @click="delPlan(item,index)"></el-link>
                                    </div>
                                </el-tooltip>
                            </template>
                        </div>
                    </div>
                </div>
            </el-form-item>
        </div>
        <div class="com_box pd_box">
            <div class="pro_title">托管规则</div>
            <el-form-item label="规则设置">
                <div class="member_box">
                    <div class="flexbox flexcenter font_14 color_01">
                        <span>符合以下</span>
                        <el-form-item label="" prop="rule_types" class="mg_l_8">
                            <el-select v-model="subForm.rule_types" placeholder="请选择" style="width:140px" @change="setSessionStorage">
                                <el-option label="任意" :value="1"></el-option>
                                <el-option label="全部" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <span class="mg_l_8">条件时生效</span>
                    </div>
                    <div class="flexbox flexcenter member_item" v-for="(item,index) in subForm.rules" :key="index">
                        <el-form-item :prop="`rules.${index}.rule_types`" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                            <el-select v-model="item.rule_types" placeholder="请选择" style="width:120px" @change="(val)=>{selectTypes(val,item)}">
                                <el-option :label="list.name" :value="list.id" v-for="list in typesList" :key="list.id" :disabled="isDisable(list)"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item :prop="`rules.${index}.rule_where`" class="mg_l_8" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                            <el-select v-model="item.rule_where" placeholder="请选择" style="width:120px" disabled>
                                <el-option label="大于等于" :value="1"></el-option>
                                <el-option label="小于等于" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item :prop="`rules.${index}.rule_values`" class="mg_l_8" :rules="formRules.checkFloat2">
                            <el-input v-model="item.rule_values" placeholder="请输入消耗" style="width:120px" @change="setSessionStorage">
                                <i slot="suffix" style="font-style:normal;color:#17233D;margin-right:5px">￥</i>
                            </el-input>
                        </el-form-item>
                        <div class="icon_btn mg_l_8" v-if="subForm.rules.length>1" @click="deletRules(index)"><img src="../../assets/img/del_icon2.svg" alt=""></div>
                    </div>
                    <el-button size="medium" style="margin-top:12px" type="text" icon="el-icon-plus" @click="addRules" :disabled="subForm.rules.length>=5">新增条件</el-button>
                </div>
            </el-form-item>
            <el-form-item label="执行操作">
                <span class="font_14 color_01">衍生计划</span>
            </el-form-item>
            <el-form-item label="检查频率">
                <span class="font_14 color_01">每5分钟</span>
            </el-form-item>
        </div>
        <div class="com_box pd_box">
            <div class="pro_title">衍生计划设置</div>
            <el-form-item label="单计划衍生总条数" :prop="`set.max_deivenumber`" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <div class="flexbox flexcenter">
                    <el-input v-model="subForm.set.max_deivenumber" placeholder="计划衍生总条数" style="width:140px" @change="setSessionStorage">
                        <i slot="suffix" style="font-style:normal;color:#17233D;margin-right:5px">条</i>
                    </el-input>
                    <div class="flexbox flexcenter color_03 mg_l_8">
                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                            <path d="M8 14C9.65684 14 11.1568 13.3284 12.2426 12.2426C13.3284 11.1568 14 9.65684 14 8C14 6.34316 13.3284 4.84316 12.2426 3.75736C11.1568 2.67157 9.65684 2 8 2C6.34316 2 4.84316 2.67157 3.75736 3.75736C2.67157 4.84316 2 6.34316 2 8C2 9.65684 2.67157 11.1568 3.75736 12.2426C4.84316 13.3284 6.34316 14 8 14Z" stroke="#B4B7BD" stroke-width="1.28" stroke-linejoin="round" />
                            <path fill-rule="evenodd" clip-rule="evenodd" d="M7.99995 4C8.44178 4 8.79995 4.35818 8.79995 4.8C8.79995 5.24182 8.44178 5.6 7.99995 5.6C7.55813 5.6 7.19995 5.24182 7.19995 4.8C7.19995 4.35818 7.55813 4 7.99995 4Z" fill="#B4B7BD" />
                            <path d="M8.15005 11V6.80005H7.85005H7.55005" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                            <path d="M7.1001 11H9.2001" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                        </svg>
                        超过设置总数后将暂停衍生计划
                    </div>
                </div>
            </el-form-item>
            <el-form-item label="单计划每次衍生" :prop="`set.deive_number`" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <el-input v-model="subForm.set.deive_number" placeholder="单计划每次衍生" style="width:140px" @change="setSessionStorage">
                    <i slot="suffix" style="font-style:normal;color:#17233D;margin-right:5px">条</i>
                </el-input>
            </el-form-item>
            <el-form-item label="单计划最多衍生" :prop="`set.max_number`" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <el-input v-model="subForm.set.max_number" placeholder="单计划最多衍生" style="width:140px" @change="setSessionStorage">
                    <i slot="suffix" style="font-style:normal;color:#17233D;margin-right:5px">次</i>
                </el-input>
            </el-form-item>
            <el-form-item label="衍生间隔" :prop="`set.deive_gap`">
                <el-radio-group v-model="subForm.set.deive_gap" @change="setSessionStorage">
                    <el-radio-button :label="1">1h</el-radio-button>
                    <el-radio-button :label="3">3h</el-radio-button>
                    <el-radio-button :label="6">6h</el-radio-button>
                    <el-radio-button :label="12">12h</el-radio-button>
                    <el-radio-button :label="24">24h</el-radio-button>
                </el-radio-group>
            </el-form-item>
            <!-- <el-form-item label="新广告组日预算" :prop="`set.day_budget`" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <el-input v-model="subForm.set.day_budget" placeholder="新广告组日预算" style="width:140px" @change="setSessionStorage">
                    <i slot="suffix" style="font-style:normal;color:#17233D;margin-right:5px">元</i>
                </el-input>
                <div class="flexbox flexcenter">
                    <span class="font_12 color_02">快捷输入：</span>
                    <el-link type="primary" :underline="false" class="mg_l_8" v-for="(item,index) in budgetFast" :key="index" @click="selectBudget(item)">{{item.name}}</el-link>
                </div>
            </el-form-item> -->
            <el-form-item label="素材优选" :prop="`set.marterial_good`">
                <el-radio-group v-model="subForm.set.marterial_good" @change="setSessionStorage">
                    <el-radio-button :label="1">是</el-radio-button>
                    <el-radio-button :label="0">否 </el-radio-button>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="衍生计划名称" :prop="`set.deive_name`" :rules="{required: true, message: '请输入', trigger: ['blur', 'change']}">
                <div class="flexbox flexcenter font_14 color_01">
                    <!-- <span>衍-</span> -->
                    <el-input class="mg_l_8" disabled v-model="subForm.set.deive_name" placeholder="请输入衍生计划名称" style="width:400px" @change="setSessionStorage">
                    </el-input>
                    <!-- <span class="mg_l_8">-<编号>-<时间></span> -->
                </div>
                <!-- <div class="flexbox flexcenter">
                    <span class="font_12 color_02">通配符：</span>
                    <el-link type="primary" :underline="false" class="mg_l_8" v-for="(item,index) in nameList" :key="index" @click="selectName(item)" :disabled="isDisableName(item)"> {{item.name}} </el-link>
                </div> -->
            </el-form-item>
        </div>
        <div class="com_box pd_box">
            <div class="pro_title">修改计划设置</div>
            <el-form-item label="是否开启" :prop="`set.ad_updata`">
                <el-radio-group v-model="subForm.set.ad_updata" @change="setSessionStorage">
                    <el-radio-button :label="1">是</el-radio-button>
                    <el-radio-button :label="0">否 </el-radio-button>
                </el-radio-group>
            </el-form-item>
            <template v-if="subForm.set.ad_updata==1">
                <el-form-item label="类型选择" :prop="`set.ad_uptypes`" class="checked_list">
                    <el-checkbox-group v-model="subForm.set.ad_uptypes" @change="setSessionStorage">
                        <el-checkbox label="1">
                            <div class="checked_item"><img src="@/assets/img/market_checked.svg" alt="" class="conversion_check">出价</div>
                        </el-checkbox>
                        <el-checkbox label="2">
                            <div class="checked_item"><img src="@/assets/img/market_checked.svg" alt="" class="conversion_check">支付roi</div>
                        </el-checkbox>
                        <el-checkbox label="3">
                            <div class="checked_item"><img src="@/assets/img/market_checked.svg" alt="" class="conversion_check">创意分类</div>
                        </el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="出价" v-if="isShow('1')" key="quote">
                    <div class="flexbox flexcenter">
                        <el-form-item  :prop="`set.quote.adjust`" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}" >
                            <el-select v-model="subForm.set.quote.adjust" placeholder="请选择" style="width:100px" @change="setSessionStorage">
                                <el-option label="上调" :value="1"></el-option>
                                <el-option label="下调" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item  :prop="`set.quote.dmin`" :rules="formRules.checkFloat" class="mg_l_8">
                            <el-input v-model="subForm.set.quote.dmin" placeholder="请输入" style="width:140px" @change="setSessionStorage"></el-input>
                        </el-form-item>
                        <div class="mg_l_8">-</div>
                        <el-form-item  :prop="`set.quote.dmax`" :rules="formRules.checkFloat" class="mg_l_8">
                            <el-input v-model="subForm.set.quote.dmax" placeholder="请输入" style="width:140px" @change="setSessionStorage"></el-input>
                        </el-form-item>
                        <div class="flexbox flexcenter color_03 mg_l_8">
                            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M8 14C9.65684 14 11.1568 13.3284 12.2426 12.2426C13.3284 11.1568 14 9.65684 14 8C14 6.34316 13.3284 4.84316 12.2426 3.75736C11.1568 2.67157 9.65684 2 8 2C6.34316 2 4.84316 2.67157 3.75736 3.75736C2.67157 4.84316 2 6.34316 2 8C2 9.65684 2.67157 11.1568 3.75736 12.2426C4.84316 13.3284 6.34316 14 8 14Z" stroke="#B4B7BD" stroke-width="1.28" stroke-linejoin="round" />
                                <path fill-rule="evenodd" clip-rule="evenodd" d="M7.99995 4C8.44178 4 8.79995 4.35818 8.79995 4.8C8.79995 5.24182 8.44178 5.6 7.99995 5.6C7.55813 5.6 7.19995 5.24182 7.19995 4.8C7.19995 4.35818 7.55813 4 7.99995 4Z" fill="#B4B7BD" />
                                <path d="M8.15005 11V6.80005H7.85005H7.55005" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                                <path d="M7.1001 11H9.2001" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                            仅在计划包含“出价”时生效,出价范围0.1-10000 <span class="text_red">(在原出价基础上调整)</span>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item label="支付roi" v-if="isShow('2')" key="play_roi">
                    <div class="flexbox flexcenter">
                        <el-form-item  :prop="`set.play_roi.adjust`" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}" >
                            <el-select v-model="subForm.set.play_roi.adjust" placeholder="请选择" style="width:100px" @change="setSessionStorage">
                                <el-option label="上调" :value="1"></el-option>
                                <el-option label="下调" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item  :prop="`set.play_roi.dmin`" :rules="formRules.checkFloat" class="mg_l_8">
                            <el-input v-model="subForm.set.play_roi.dmin" placeholder="请输入" style="width:140px" @change="setSessionStorage"></el-input>
                        </el-form-item>
                        <div class="mg_l_8">-</div>
                        <el-form-item  :prop="`set.play_roi.dmax`" :rules="formRules.checkFloat" class="mg_l_8">
                            <el-input v-model="subForm.set.play_roi.dmax" placeholder="请输入" style="width:140px" @change="setSessionStorage"></el-input>
                        </el-form-item>
                        <div class="flexbox flexcenter color_03 mg_l_8">
                            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M8 14C9.65684 14 11.1568 13.3284 12.2426 12.2426C13.3284 11.1568 14 9.65684 14 8C14 6.34316 13.3284 4.84316 12.2426 3.75736C11.1568 2.67157 9.65684 2 8 2C6.34316 2 4.84316 2.67157 3.75736 3.75736C2.67157 4.84316 2 6.34316 2 8C2 9.65684 2.67157 11.1568 3.75736 12.2426C4.84316 13.3284 6.34316 14 8 14Z" stroke="#B4B7BD" stroke-width="1.28" stroke-linejoin="round" />
                                <path fill-rule="evenodd" clip-rule="evenodd" d="M7.99995 4C8.44178 4 8.79995 4.35818 8.79995 4.8C8.79995 5.24182 8.44178 5.6 7.99995 5.6C7.55813 5.6 7.19995 5.24182 7.19995 4.8C7.19995 4.35818 7.55813 4 7.99995 4Z" fill="#B4B7BD" />
                                <path d="M8.15005 11V6.80005H7.85005H7.55005" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                                <path d="M7.1001 11H9.2001" stroke="#B4B7BD" stroke-width="1.28" stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                            仅在计划优化目标为“支付ROI”是生效,支付ROI范围0.1-100
                        </div>
                    </div>
                </el-form-item>
                <el-form-item label="创意分类" v-if="isShow('3')" key="class">
                    <div class="flexbox flexcenter class_item" v-for="(item,index) in subForm.set.class" :key="index">
                        <el-form-item  :prop="`set.class.${index}.idStr`" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                            <el-cascader @change="setSessionStorage" v-model="item.idStr" :options="industryList" ref="industryRef" :props="{label:'industry_name',value:'industry_id',}" style="width:220px"></el-cascader>
                        </el-form-item>
                        <div class="icon_btn mg_l_8"  @click="deleteClass(index)" v-if="subForm.set.class.length >1"><img src="../../assets/img/del_icon2.svg" alt=""></div>
                    </div>
                    <el-button size="medium" type="text" icon="el-icon-plus" @click="addClass">新增分类</el-button>
                </el-form-item>
            </template>
        </div>
        <div class="com_box pd_box">
            <div class="pro_title">通知设置</div>
            <el-form-item label="通知人员" prop="notice" class="mg_l_8" :rules="{required: true, message: '请选择', trigger: ['blur', 'change']}">
                <el-select v-model="subForm.notice" placeholder="请选择" multiple collapse-tags filterable style="width:220px" @change="setSessionStorage">
                    <el-option :label="item.nickname" :value="item.id" v-for="item in optimizerList" :key="item.id"></el-option>
                </el-select>
            </el-form-item>
        </div>
    </div>
</template>

<script>
export default {
    props: ["subForm"],
    name: "",
    data() {
        return {
            source: null,
            is_all: false,
            userQeury: {
                page: 1,
                limit: 20,
                advertiser_id: "",
            },
            u_loading: false,
            userList: [],
            user_count: 0,

            planQeury: {
                page: 1,
                limit: 100,
                advertiser_id: [],
                ad_id: "",
            },
            p_loading: false,
            planList: [],
            plan_count: 0,
            optimizerList: [],
            industryList:[],
            formRules: {
                checkFloat: [
                    {
                        pattern:
                            /^(([1-9][0-9]*)(\.\d{1,1})?|0\.\d{1,1})$/,
                        required: true,
                        message: "请输入正确数值",
                        trigger: ["blur", "change"],
                    },
                ],
                checkFloat2: [
                    {
                        pattern:
                            /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
                        required: true,
                        message: "请输入正确数值",
                        trigger: ["blur", "change"],
                    },
                ],
            },
            budgetFast: [
                {
                    name: "￥300",
                    id: 300,
                },
                {
                    name: "￥500",
                    id: 500,
                },
                {
                    name: "￥1000",
                    id: 1000,
                },
                {
                    name: "￥5000",
                    id: 5000,
                },
            ],
            nameList: [
                {
                    name: "+ 原计划名称",
                    value: "<原计划名称>",
                },
            ],
            typesList: [
                {
                    name: "消耗",
                    id: 1,
                },
                {
                    name: "直接支付ROI",
                    id: 2,
                },
                {
                    name: "转化成本",
                    id: 3,
                },
                {
                    name: "成交订单金额",
                    id: 4,
                },
                {
                    name: "成交订单数",
                    id: 5,
                },
            ],
        };
    },
    created() {
        this.getUser();
        this.getOptimizer();
        this.getIndustryList()
    },
    computed: {},
    methods: {
        //获取优化师
        async getOptimizer() {
            const { data: res } = await this.$http.post(
                "/videotest/Probject/szOptimizerList",
                this.userQeury
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.optimizerList = res.data;
            }
        },

        //获取账户
        async getUser(page) {
            this.userQeury.page = page;
            this.u_loading = true;
            const { data: res } = await this.$http.post(
                "/autodrop/Derive/advertiserList",
                this.userQeury
            );
            if (res.code !== 200) {
                this.u_loading = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.u_loading = false;
                this.userList = res.data.list;
                this.user_count = res.data.count;
            }
        },
        // 账户分页
        userChange(val) {
            this.getUser(val);
        },

        // 选择账户
        selectUser() {
            this.getPlan(1);
        },

        //获取计划
        async getPlan(page) {
            let that = this;
            if (that.source) {
                that.source();
            }

            this.planQeury.page = page;
            this.p_loading = true;
            const { data: res } = await this.$http.post(
                "/autodrop/Derive/adList",
                this.planQeury,
                {
                    cancelToken: new axios.CancelToken(function executor(c) {
                        that.source = c;
                    }),
                }
            );
            if (res.code !== 200) {
                this.p_loading = false;
                this.$message.error(res.msg);
                return;
            } else {
                this.is_all = false;
                for (let i in res.data.list) {
                    res.data.list[i].check = false;
                }
                for (let i in this.subForm.ad_ids) {
                    for (let a in res.data.list) {
                        if (
                            this.subForm.ad_ids[i].ad_id ==
                            res.data.list[a].ad_id
                        ) {
                            res.data.list[a].check = true;
                        }
                    }
                }
                this.p_loading = false;
                this.planList = res.data.list;
                this.plan_count = res.data.count;
            }
        },
        // 账户分页
        planChange(val) {
            this.getPlan(val);
        },

        // 全选计划
        selectAll(val) {
            this.planList.map((item) => {
                item.check = val;
            });
            if (val) {
                let arr = this.arrRepeat(this.subForm.ad_ids, this.planList);
                this.subForm.ad_ids = arr;
            } else {
                this.clearAll(this.subForm.ad_ids, this.planList);
            }
            this.setSessionStorage();
        },

        clearAll(arr1, arr2) {
            for (let i in arr1) {
                for (let a in arr2) {
                    if (arr1[i].ad_id == arr2[a].ad_id) {
                        arr1.splice(i, 1);
                    }
                }
            }
        },

        // 数组去重
        arrRepeat(old, news) {
            let k = {};
            let arr = [...old, ...news];
            let newsArr = [];
            newsArr = arr.reduce(function (cur, next) {
                k[next.ad_id]
                    ? ""
                    : (k[next.ad_id] =
                          true &&
                          cur.push({
                              name: next.name,
                              ad_id: next.ad_id,
                          }));
                return cur;
            }, []);
            return newsArr;
        },

        // 选择计划
        checkPlan(item) {
            if (item.check) {
                this.subForm.ad_ids.push({
                    name: item.name,
                    ad_id: item.ad_id,
                });
            } else {
                let index = this.subForm.ad_ids.findIndex(
                    (val) => val.ad_id == item.ad_id
                );
                this.subForm.ad_ids.splice(index, 1);
            }
            this.setSessionStorage();
        },
        // 删除计划
        delPlan(item, index) {
            let $index = this.planList.findIndex(
                (val) => val.ad_id == item.ad_id
            );
            this.subForm.ad_ids.splice(index, 1);
            if ($index !== -1) {
                this.planList[$index].check = false;
            }
            this.setSessionStorage();
        },
        // 清空计划
        clearPlan() {
            this.subForm.ad_ids = [];
            this.planList.map((item) => {
                item.check = false;
            });
            this.is_all = false;
            this.setSessionStorage();
        },
        // 添加规则
        addRules() {
            // if (this.subForm.rules.length >= 5) {
            //     return;
            // } else {
            //     this.subForm.rules.push({
            //         rule_types: null,
            //         rule_where: null,
            //         rule_values: null,
            //     });
            // }
            this.subForm.rules.push({
                rule_types: null,
                rule_where: null,
                rule_values: null,
            });
            this.setSessionStorage();
        },
        // 删除规则
        deletRules(index) {
            // if (this.subForm.rules.length <= 1) {
            //     return;
            // } else {
            //     this.subForm.rules.splice(index, 1);
            // }
            this.subForm.rules.splice(index, 1);
            this.setSessionStorage();
        },

        //获取分类列表
        async getIndustryList() {
            const { data: res } = await this.$http.post(
                "launch/Getinfo/industry_list"
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.industryList = this.treeData(res.data);
            }
        },
        // 创意分类树形结构
        treeData(arr) {
            let first = [];
            arr.forEach((item) => {
                if (item.level == 1) {
                    first.push(item);
                }
            });
            first.forEach((item) => {
                item.children = [];
                arr.forEach((i) => {
                    if (
                        item.first_industry_id == i.first_industry_id &&
                        i.level == 2
                    ) {
                        item.children.push(i);
                    }
                });
            });
            first.forEach((item) => {
                item.children.forEach((i) => {
                    i.children = [];
                    arr.forEach((a) => {
                        if (
                            i.second_industry_id == a.second_industry_id &&
                            a.level == 3
                        ) {
                            i.children.push(a);
                        }
                    });
                });
            });
            return first;
        },

        // 添加分类
        addClass(){
            this.subForm.set.class.push({
                idStr:[]
            })
            this.setSessionStorage();
        },

        // 删除分类
        deleteClass(index){
            this.subForm.set.class.splice(index,1)
            this.setSessionStorage();
        },

        isShow(types){
            let is_true = false
            if(this.subForm.set.ad_uptypes.includes(types)){
                is_true = true
            }
            return is_true
        },

        // 选择规则
        selectTypes(val, item) {
            if (val == 3) {
                item.rule_where = 2;
            } else {
                item.rule_where = 1;
            }
            this.setSessionStorage();
        },

        isDisable(item) {
            let is_true = false;
            for (let i in this.subForm.rules) {
                if (this.subForm.rules[i].rule_types == item.id) {
                    is_true = true;
                }
            }
            return is_true;
        },

        isDisableName(item) {
            let is_true = false;
            let index = this.subForm.set.deive_name.search(item.value);
            if (index != -1) {
                is_true = true;
            }
            return is_true;
        },

        // 快捷输入
        selectBudget(item) {
            this.subForm.set.day_budget = item.id;
            this.setSessionStorage();
        },

        selectName(item) {
            this.subForm.set.deive_name =
                this.subForm.set.deive_name + item.value;
            this.setSessionStorage();
        },

        setSessionStorage() {
            this.$emit("setSessionStorage");
        },
    },
    components: {},
};
</script>


<style scoped>
.mg_l_12 {
    margin-left: 12px;
}
.mg_l_8 {
    margin-left: 8px;
}
.pd_box {
    padding: 0 20px;
    overflow: hidden;
    margin-bottom: 12px;
}
.pro_title {
    font-weight: bold;
    font-size: 16px;
    height: 56px;
    line-height: 56px;
}

.member_box {
    border: 1px solid #ebebeb;
    border-radius: 2px;
    padding: 16px 20px;
}
.mem_title {
    width: 88px;
    font-size: 14px;
    color: #17233d;
}
.member_item {
    margin-top: 12px;
}
.member_tag {
    background: rgba(165, 177, 209, 0.05);
    border-radius: 2px;
    width: 60px;
    height: 22px;
    text-align: center;
    line-height: 22px;
    font-size: 13px;
    color: #616c85;
    margin-left: 12px;
}
.icon_btn {
    margin-left: 12px;
}
.line_one {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
}

.com_check {
    width: 214px;
    border-top: 1px solid #ebebeb;
    border-left: 1px solid #ebebeb;
    border-bottom: 1px solid #ebebeb;
    height: 355px;
}
.com_check.border_r {
    border-right: 1px solid #ebebeb;
}
.check_head {
    height: 40px;
    border-bottom: 1px solid #ebebeb;
    padding: 0 12px;
    line-height: 40px;
    font-size: 13px;
    color: #17233d;
}
.check_search {
    padding: 12px 12px 0 12px;
}
.all_check {
    padding: 0 12px;
}
.check_content {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 12px;
}

.user_check {
    width: 100%;
    overflow-x: hidden;
}
.user_check .el-checkbox {
    display: flex;
    align-items: center;
    margin-top: 12px;
}
/deep/ .user_check .el-checkbox .el-checkbox__label {
    display: inline;
    font-size: 14px;
    color: #666;
    width: 100%;
    height: 100%;
    overflow: hidden;
    line-height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.span-item {
    display: block;
    height: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.has_item {
    height: 32px;
    margin-top: 8px;
    padding: 0 4px;
    background: rgba(165, 177, 209, 0.08);
    border-radius: 2px;
}
.page_footer {
    height: 22px;
    padding: 0 5px;
}
.class_item{
    margin-bottom: 12px;
}
/deep/ .page_footer .el-pagination {
    padding: 0;
}
/deep/ .page_footer .el-pagination__total {
    margin-right: 5px;
    font-size: 12px;
}
/deep/ .page_footer .el-pagination button {
    padding: 0 0px;
    min-width: 15px;
}
/deep/ .page_footer .el-pager li {
    min-width: 15px;
}
</style>

<style>
.derive_form .el-form-item__label {
    color: #616c85 !important;
}
.derive_form .el-form-item__label {
    line-height: 16px !important;
    margin-top: 7px;
}
.derive_form .set_style .el-form-item__label {
    margin-top: 0;
}
</style>

